import React, { useState, useEffect } from 'react';
import { getData } from '@/api';

import TableView from '@/components/TableView';

interface TableRowData {
  id: string;
  name: string;
  quotas: number;
  lenders: number;
  cycle: number;
  score: number;
  returned: number;
}

interface TableData {
  id: string;
  title: string;
  list: TableRowData[];
}
const Home: React.FC = () => {
  // 列表数据
  const [tableDatas, setTableDatas] = useState<TableData[]>([]);

  const getDataFn = () => {
    // 获取风控数据
    getData().then(res => {
      console.log(res);
      if (res.data.code == 200) {
        setTableDatas(res.data.data)
      } else {
        setTableDatas([])
        console.log("数据获取失败！")
      }
    })
  }
  const callBack = () => {
    getDataFn();
  }
  // 获取数据
  useEffect(() => {
    getDataFn();
  }, []);
  return (
    <>
      {
        tableDatas.length && <TableView tableDatas={tableDatas[0]} callBack={callBack} />
      }
    </>
  );
};

export default Home;